package user.notifier;

import java.util.ArrayList;
import java.util.List;


import user.UserIF;
import user.blog.Blog;

public class NotifierManager {


	List<Announcements>announcements;
	
	public NotifierManager(){
		announcements = new ArrayList<Announcements>();
	}
	

	public int getNumberOfAnnouncements(String sessionId) {
		
		
		int notificadores = 0;
		
		for(Announcements notificador : announcements)
			if(notificador.getIdUserID().equals(sessionId))
				notificadores += 1;		
		
		return notificadores;
	}
	
		
	public void addPostAnnouncements(String sessionId, String blogId) {
		this.announcements.add(new Announcements(sessionId, blogId));
	}
	
	public void modifiedBlog(String blogId, String postId){
		for(Announcements notificador : announcements){

			if(notificador.getIdBlog().equals(blogId))
				notificador.setIdPostCreat(postId);
		}
	}
	
	
	
	
	public String getAnnouncement(String sessionId, int index)throws Exception {
		int indice = 0;
		
		
		if(sessionId == null
				|| sessionId.equals(""))				
				throw new Exception("Sessão inválida");
		
		if(index < 0)
			throw new Exception("Índice inválido");
				
		for(Announcements notificador : announcements)
			if(notificador.getIdUserID().equals(sessionId))
				if(index == indice)
					return notificador.getIdAnnouncement();
			
			
				
		return null;
	}
	
	public String getPostJustCreated(String announcementId) {
		
		for(Announcements notificador : announcements){
			System.out.println("AnID = "+notificador.getIdAnnouncement());
			if(notificador.getIdAnnouncement().equals(announcementId))
				return notificador.getIdPostCreat();
		}
		return null;
	}
	
	public void deleteAnnouncement(String sessionId, String announcementId) {

		for(Announcements notificador : announcements)
			if(notificador.getIdAnnouncement().equals(announcementId)
					&& notificador.getIdUserID().equals(sessionId)){
				this.announcements.remove(notificador);
				break;
			}
					
		
	}
	
	/*public boolean logoff(String sessionID) throws Exception {
		return session.logoffUser(sessionID);
	}*/
	
	public void saveData() {
		// TODO
	}


	public List<Announcements> getAnnouncements() {
		return announcements;
	}


	public void setAnnouncements(List<Announcements> announcements) {
		this.announcements = announcements;
	}
	
	
}
